﻿using netDxf;
using netDxf.Entities;
using netDxf.Header;
using netDxf.Tables;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TestDxfDocument

{
    class ISYC_308_08
    {
        //图F.90 ISYC_308_08-可转位刀片心轴连接三面刃单角槽铣刀
        public static void ISYC_308_08_j(Dictionary<string, Object> data)  //  可转位刀片心轴连接三面刃单角槽铣刀
        {

            DxfDocument dxf = new DxfDocument();
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中心线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan }; //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层
            double pi = Math.PI;
            string path = Convert.ToString(data["path"]);
            double sl_ = Convert.ToDouble(data["dc"]);
            double scale = Convert.ToDouble(data["scale"]);
            //double sl_ = 45;
            //double scale = 1;
            if (sl_ <= 67)
            {
                scale = 4;
            }
            else if (67 < sl_ && sl_ <= 75)
            {
                scale = 2.5;
            }
            else if (75 < sl_ && sl_ <= 100)
            {
                scale = 2;
            }
            else
            {
                scale = 1;
            }
           /*
            double dhub = 40*scale ;
            double thub = 26 * scale;
            double oal = 26.5 * scale;
            double dc = 120 * scale;
            double dcn = 110 * scale;

            double kapr = 70;
            */
            double dhub = Convert.ToDouble(data["dhub"]) * scale;
            double thub = Convert.ToDouble(data["thub"]) * scale;
            double oal = Convert.ToDouble(data["oal"]) * scale;
            double dc = Convert.ToDouble(data["dc"]) * scale;
            double dcn = Convert.ToDouble(data["dcn"]) * scale;

            double kapr = Convert.ToDouble(data["kapr"]);
            double kapr_ = kapr * pi / 180;
            Vector2 p0 = new Vector2(0, 0);
            Vector2 p0_1 = fun.Polar(p0, pi, oal - thub);
            Vector2 p0_2 = fun.Polar(p0, 0, oal);
            Vector2 p1 = fun.Polar(p0, pi / 2, dhub / 2.0);
            Vector2 p2 = fun.mirrorpoint(p1, p0_1, p0_2);
            Vector2 p3 = fun.Polar(p1, 0, thub);
            Vector2 p4 = fun.mirrorpoint(p3, p0_1, p0_2);
            Vector2 p5 = new Vector2(thub / 9.0, dcn / 2.0);
            Vector2 p6 = fun.mirrorpoint(p5, p0_1, p0_2);
            Vector2 p7 = fun.Polar(p5, (pi / 2 - kapr_), ((dc - dcn) / 2.0) / Math.Sin((pi / 2 - kapr_)));
            Vector2 p8 = fun.mirrorpoint(p7, p0_1, p0_2);
            Vector2 p9 = fun.Inters(p5, p6, p1, p3);
            Vector2 p10 = fun.Inters(p2, p4, p5, p6);
            Vector2 p11 = fun.Inters(p7, p8, p1, p3);
            Vector2 p12 = fun.Inters(p2, p4, p7, p8);
            Vector2 p13 = fun.Polar(p7, fun.CalAngle(p7, p5), fun.CalDistance(p7, p5) / 2.0);
            Vector2 p14 = fun.Polar(p13, fun.CalAngle(p13, p7) - pi / 3, fun.CalDistance(p13, p7) / 1.5);
            Vector2 p15 = fun.mirrorpoint(p13, p0_1, p0_2);
            Vector2 p16 = fun.mirrorpoint(p14, p0_1, p0_2);
            Vector2 p17 = fun.Polar(p13, fun.CalAngle(p14, p13) + pi / 2, 0.5 / 7.3 * fun.CalDistance(p7, p13));
            Vector2 p18_1 = fun.Polar(p17, fun.CalAngle(p14, p13), dc);
            Vector2 p18 = fun.Polar(p13, fun.CalAngle(p7, p13) - pi / 2, 0.5 / 7.3 * fun.CalDistance(p7, p13));
            Vector2 p19_1 = fun.Polar(p18, fun.CalAngle(p7, p13), dc);
            Vector2 p19 = fun.Inters(p17, p18_1, p19_1, p18);
            Vector2 p20 = fun.Polar(p14, fun.CalAngle(p14, p7) - pi / 2, 0.5 / 4.873 * fun.CalDistance(p13, p14));
            Vector2 p21_1 = fun.Polar(p19, fun.CalAngle(p13, p14), dc);
            Vector2 p21_2 = fun.Polar(p20, fun.CalAngle(p7, p14), dc);
            Vector2 p21 = fun.Inters(p20, p21_2, p19, p21_1);
            Vector2 p22_1 = fun.Polar(p19, fun.CalAngle(p13, p7), dc);
            Vector2 p22_2 = fun.Polar(p21, fun.CalAngle(p14, p7), dc);
            Vector2 p22 = fun.Inters(p22_1, p19, p22_2, p21);
            Vector2 p23 = fun.Inters(p22, p21, p7, p8);
            Vector2 p24 = fun.mirrorpoint(p19, p0_1, p0_2);
            Vector2 p25 = fun.mirrorpoint(p22, p0_1, p0_2);
            Vector2 p26 = fun.mirrorpoint(p21, p0_1, p0_2);
            Vector2 p27 = fun.Inters(p24, p26, p6, p8);
            Vector2 p28 = fun.Inters(p7, p8, p25, p26);
            Vector2 p29_0 = fun.Polar(p0, pi, oal - thub);
            Vector2 p29 = fun.Polar(p29_0, pi / 2, p5.Y / 3.0 * 2);
            Vector2 p30 = fun.Polar(p29, fun.CalAngle(p19, p21), fun.CalDistance(p19, p21));
            Vector2 p31 = fun.Polar(p30, fun.CalAngle(p21, p22), fun.CalDistance(p21, p22));
            Vector2 p32 = fun.Polar(p29, fun.CalAngle(p19, p13), fun.CalDistance(p19, p13));
            Vector2 p33 = fun.Polar(p32, fun.CalAngle(p13, p14), fun.CalDistance(p13, p14));
            Vector2 p34 = fun.Polar(p32, fun.CalAngle(p13, p7), fun.CalDistance(p13, p7));
            Vector2 p35 = fun.Inters(p29, p30, p5, p6);
            Vector2 p36 = fun.Inters(p29, p31, p5, p6);
            Vector2 p37 = fun.mirrorpoint(p29, p0_1, p0_2);
            Vector2 p38 = fun.mirrorpoint(p30, p0_1, p0_2);
            Vector2 p39 = fun.mirrorpoint(p31, p0_1, p0_2);
            Vector2 p40 = fun.mirrorpoint(p32, p0_1, p0_2);
            Vector2 p41 = fun.mirrorpoint(p33, p0_1, p0_2);
            Vector2 p42 = fun.mirrorpoint(p34, p0_1, p0_2);
            Vector2 p43 = fun.Inters(p5, p6, p37, p38);
            Vector2 p44 = fun.Inters(p5, p6, p37, p39);
            Vector2 p45 = fun.Polar(p22, pi / -2, dc / 2.0);
            Vector2 p46 = fun.Polar(p45, fun.CalAngle(p22, p21), fun.CalDistance(p22, p21));
            Vector2 p47_1 = fun.Polar(p46, fun.CalAngle(p21, p19), dc);
            Vector2 p47_2 = fun.Polar(p45, fun.CalAngle(p22, p19), dc);
            Vector2 p47 = fun.Inters(p45, p47_2, p46, p47_1);
            Vector2 p48 = fun.Inters(p7, p8, p46, p45);
            Vector2 p49 = fun.Inters(p7, p8, p47, p45);
            Vector2 p50_1 = fun.Polar(p46, fun.CalAngle(p46, p45) + pi / 2, 0.05 / 0.6577 * fun.CalDistance(p47, p46));
            Vector2 p50_2 = fun.Polar(p50_1, fun.CalAngle(p46, p45), dc);
            Vector2 p50_3 = fun.Polar(p47, fun.CalAngle(p47, p46) + pi / 2, 0.05 / 0.6577 * fun.CalDistance(p47, p46));
            Vector2 p50_4 = fun.Polar(p50_3, fun.CalAngle(p47, p46), dc);
            Vector2 p50_5 = fun.Polar(p47, fun.CalAngle(p47, p45) - pi / 2, 0.05 / 0.6577 * fun.CalDistance(p47, p46));
            Vector2 p50_6 = fun.Polar(p50_5, fun.CalAngle(p47, p45), dc);
            Vector2 p50 = fun.Inters(p50_1, p50_2, p50_3, p50_4);
            Vector2 p51 = fun.Inters(p50_3, p50_4, p50_5, p50_6);
            Vector2 p52 = fun.Inters(p50_1, p50_2, p50_5, p50_6);
            Vector2 p53 = fun.Polar(p21, fun.CalAngle(p21, p22), fun.CalDistance(p21, p22) / 2.0);
            Vector2 p54 = fun.Polar(p19, fun.CalAngle(p19, p22), fun.CalDistance(p19, p22) / 2.0);
            Vector2 p55 = fun.Inters(p19, p53, p21, p54);
            Vector2 p56 = fun.Polar(p32, fun.CalAngle(p13, p55), fun.CalDistance(p13, p55));
            Vector2 p57 = fun.mirrorpoint(p56, p0_1, p0_2);
            Vector2 p58 = fun.Polar(p51, fun.CalAngle(p13, p55), fun.CalDistance(p13, p55));
            var polyline1 = Pus.AddPointsToLwPolyLine(p5, p17, p19, p22, p21, p19, p22, p23, p11, p3, p4, p12, p48, p46, p47, p45, p46, p47, p49, p11, p49, p45, p48, p8, p28, p25, p24, p27, p8, p6,
                p44, p37, p38, p39, p37, p43, p10, p2, p1, p9, p10, p35, p29, p31, p30, p29, p36, p5);
            var polyline2 = Pus.AddPointsToLwPolyLine(p19, p22, p21, p19);
            var polyline3 = Pus.AddPointsToLwPolyLine(p13, p7, p14, p13);
            var polyline4 = Pus.AddPointsToLwPolyLine(p32, p33, p34, p32);
            var polyline5 = Pus.AddPointsToLwPolyLine(p40, p41, p42, p40);
            var polyline6 = Pus.AddPointsToLwPolyLine(p50, p51, p52, p50);
            Circle circle2 = new Circle(Pus.ToV3(p55, 0), fun.CalDistance(p13, p14) / 8.0);//圆
            Circle circle3 = new Circle(Pus.ToV3(p56, 0), fun.CalDistance(p13, p14) / 8.0);//圆
            Circle circle4 = new Circle(Pus.ToV3(p57, 0), fun.CalDistance(p13, p14) / 8.0);//圆
            Circle circle5 = new Circle(Pus.ToV3(p58, 0), fun.CalDistance(p13, p14) / 8.0);//圆

            dxf.AddEntity(new EntityObject[] { polyline1 ,polyline2 ,polyline3 ,polyline4 ,polyline5 ,polyline6
                ,circle2,circle3,circle4,circle5
            });
            fun.PolyFill(dxf, polyline1, 0.5, contour);
            fun.PolyFill(dxf, polyline2, 0.5, contour);
            fun.PolyFill(dxf, polyline3, 0.5, contour);
            fun.PolyFill(dxf, polyline4, 0.5, contour);
            fun.PolyFill(dxf, polyline5, 0.5, contour);
            fun.PolyFill(dxf, polyline6, 0.5, contour);
            //标注

            Vector2 v1 = fun.Polar(p9, pi / 2, dc / 4.0);
            Vector2 v0_1 = fun.Polar(p0, pi / 2, dhub / 4);
            Vector2 v0_2 = fun.Polar(v0_1, 0, oal);
            Vector2 v0_3 = fun.Polar(p0, pi / -2, dhub / 4);
            Vector2 v0_4 = fun.Polar(v0_3, 0, oal);
            Vector2 v2 = fun.Polar(v0_4, 0, oal / 4.0);
            Vector2 v3 = fun.Polar(v2, -80 * pi / 180, oal / 2.0);
            Vector2 v4 = fun.Polar(v3, -80 * pi / 180, oal / 2.0);
            Vector2 v5 = fun.Polar(p0_1, pi / 2, dc / 2.0);
            Vector2 v6 = fun.Polar(v5, pi - 10 * pi / 180, 0.5 * 1.7 * scale);
            Vector2 v7 = fun.Polar(v6, pi - 10 * pi / 180, oal);
            Vector2 v8 = fun.Polar(p0, pi + pi / 3, 1.7 * 0.5 * scale);
            Vector2 v9 = fun.Polar(v8, pi + pi / 3, oal / 2.0);
            Vector2 v10 = fun.Polar(v9, pi / -2, 1.2 * scale);
            Vector2 v11 = fun.Polar(p0_2, -80 * pi / 180, 1.7 * 0.5 * scale);
            Vector2 v12 = fun.Polar(v11, -80 * pi / 180, oal * 2);
            Vector2 v13 = fun.Polar(v12, pi / -2, 1.2 * scale);



            fun.dimrot1(dxf, p0, p0_2, 0, oal * 3.5, 2, 1.6 * scale, 2 * scale, 0.9, "OAL", "", "");
            fun.dimrot1(dxf, p22, p0_1, 0, oal * 1.5, 2, 1.6 * scale, 2 * scale, 0.9, "CWN", "", "");
            fun.dimrot1(dxf, p22, p25, 90, oal * 2, 2, 1.6 * scale, 2 * scale, 0.9, "DC", "", "");
            fun.dimrot1(dxf, p7, p8, 90, oal * 1.5, 2, 1.6 * scale, 2 * scale, 0.9, "BD", "", "");
            fun.dimrot1(dxf, p22, p3 , 90, oal, 2, 1.6 * scale, 2 * scale, 0.9, "CDX", "", "");
            fun.dimrot1(dxf, p1, p3, 180, oal / 2.0, 2, 1.6 * scale, 2 * scale, 0.9, "THUB", "", "");
            fun.dimrot1(dxf, p3, p4, -90, oal, 2, 1.6 * scale, 2 * scale, 0.9, "DHUB", "", "");
            fun.dimrot1(dxf, v0_2, v0_4, -90, oal / 2.0, 2, 1.6 * scale, 2 * scale, 0.9, "DCON", "", "");
            fun.jdbz2(dxf, new Line(p19, p22), new Line(p0_1, fun.Polar(p0_1, pi / 2, dc / 2)), oal * 1.2, 1.6 * scale, 2 * scale, 0.9, "KAPR", "", "");
          /*  fun.Singlelinearrow(dxf, "CCMS", v2, -80, v3, v4, 1.6 * scale, 2 * scale);
            fun.Axis(dxf, fun.Polar(p0_2, -pi / 4, oal * 1.5), 0, -90, "Z", "X", "Y", 0.5 * scale, 1.6 * scale, 1);
            fun.Axis(dxf, p0_1, 0, -90, "", "", "", 0.5 * scale, 1.6 * scale, 1);
            fun.Axis(dxf, p0_2, 0, -90, "", "", "", 0.5 * scale, 1.6 * scale, 1);*/
            Line linev1 = new Line(v7, v6);
            Text txt1 = new Text("CRP", v7, 1.6 * scale, 0);
            Line linev2 = new Line(v9, v8);
            Text txt2 = new Text("CIP", v10, 1.6 * scale, 0);
            Line linev3 = new Line(v11, v12);
            Text txt3 = new Text("PCS,MCS", v13, 1.6 * scale, 0);
            Circle circle1 = new Circle(Pus.ToV3(v5, 0), 0.5 * 1.7 * scale);//圆
           /* dxf.AddEntity(new EntityObject[] {linev1, txt1,linev2,txt2,linev3,txt3,circle1
            });*/
            Line line3 = new Line(v0_1, v0_2);
            line3.Lineweight = Lineweight.W35;//Lineweight指线宽
            line3.Layer = additionalline;//Layer指图层
            line3.LinetypeScale = 5 * scale;//指线性比例
            line3.Linetype = Linetype.Dashed;//Linetype指是点划线还是虚线什么的
            dxf.AddEntity(line3); //提取
            Line line4 = new Line(v0_3, v0_4);
            line4.Lineweight = Lineweight.W35;//Lineweight指线宽
            line4.Layer = additionalline;//Layer指图层
            line4.LinetypeScale = 5 * scale;//指线性比例
            line4.Linetype = Linetype.Dashed;//Linetype指是点划线还是虚线什么的
            dxf.AddEntity(line4); //提取
            Line line5 = new Line(p0_1, p0_2);
            line5.Lineweight = Lineweight.W25;//Lineweight指线宽
            line5.Layer = centre;//Layer指图层
            line5.LinetypeScale = 5*scale ;//指线性比例
            line5.Linetype = Linetype.DashDot;//Linetype指是点划线还是虚线什么的
            dxf.AddEntity(line5); //提取

            double isframe = Convert.ToInt32(data["isframe"]);
            String isframe_chose = Convert.ToString(data["isframe_chose"]);
            if (isframe == 1)
            {
                if (isframe_chose.Equals("0"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA0X(dxf, new Vector2(p0.X - 1189 / 2.0, p0.Y + 841 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("1"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA1X(dxf, new Vector2(p0.X - 841 / 2.0, p0.Y + 594 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("2"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA2X(dxf, new Vector2(p0.X - 594 / 2.0, p0.Y + 420 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("3"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA3X(dxf, new Vector2(p0.X - 420 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4X"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4X(dxf, new Vector2(p0.X - 297 / 2.0, p0.Y + 210 / 2.0 - 10 * 2.26), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4Y"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4Y(dxf, new Vector2(p0.X - 210 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }
            }

            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }



    }
}


